package internal

import (
	"context"
	"github.com/gogf/gf/v2/database/gdb"
	"github.com/gogf/gf/v2/frame/g"
)

type RolePermissionDao struct {
	table     string                // 表名称
	group     string                // 数据源分组，默认default
	columns   RolePermissionColumns // 表字段
	columnMap map[string]string     //表字段map
}

// RolePermissionColumns defines and stores column names for table gen_database.
type RolePermissionColumns struct {
	Id             string //
	TenantCode     string //租户编码
	RoleCode       string //角色编码
	PermissionCode string //API编码
	Creator        string //创建人
	CreatorId      string //创建人id
	CreateDate     string //创建时间
	Modifier       string //修改者
	ModifierId     string //修改者id
	ModifyDate     string //修改时间
	State          string //状态（1正常 0停用）
	VersionNumber  string //版本号
}

//  rolePermissionColumns holds the columns for table mes_gf_mst_yield_line.
var rolePermissionColumns = RolePermissionColumns{
	Id:             "id",              //
	TenantCode:     "tenant_code",     //租户编码
	RoleCode:       "role_code",       //角色编码
	PermissionCode: "permission_code", //API编码
	Creator:        "creator",         //创建人
	CreatorId:      "creator_id",      //创建人id
	CreateDate:     "create_date",     //创建时间
	Modifier:       "modifier",        //修改者
	ModifierId:     "modifier_id",     //修改者id
	ModifyDate:     "modify_date",     //修改时间
	State:          "state",           //状态（1正常 0停用）
	VersionNumber:  "version_number",  //版本号
}
var rolePermissionColumnMap = map[string]string{
	"Id":             "id",              //
	"TenantCode":     "tenant_code",     //租户编码
	"RoleCode":       "role_code",       //角色编码
	"PermissionCode": "permission_code", //API编码
	"Creator":        "creator",         //创建人
	"CreatorId":      "creator_id",      //创建人id
	"CreateDate":     "create_date",     //创建时间
	"Modifier":       "modifier",        //修改者
	"ModifierId":     "modifier_id",     //修改者id
	"ModifyDate":     "modify_date",     //修改时间
	"State":          "state",           //状态（1正常 0停用）
	"VersionNumber":  "version_number",  //版本号
}

// NewRolePermissionDao creates and returns a new DAO object for table data access.
func NewRolePermissionDao() *RolePermissionDao {
	return &RolePermissionDao{
		group:     "default",
		table:     "sys_role_permission",
		columns:   rolePermissionColumns,
		columnMap: rolePermissionColumnMap,
	}
}

// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *RolePermissionDao) DB() gdb.DB {
	return g.DB(dao.group)
}

// Table returns the table name of current dao.
func (dao *RolePermissionDao) Table() string {
	return dao.table
}

// Columns returns all column names of current dao.
func (dao *RolePermissionDao) Columns() RolePermissionColumns {
	return dao.columns
}

// ColumnMap returns all column map of current dao.
func (dao *RolePermissionDao) ColumnMap() map[string]string {
	return dao.columnMap
}

// Group returns the configuration group name of database of current dao.
func (dao *RolePermissionDao) Group() string {
	return dao.group
}

// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *RolePermissionDao) Ctx(ctx context.Context) *gdb.Model {
	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}

// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *RolePermissionDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) {
	return dao.Ctx(ctx).Transaction(ctx, f)
}
